;MASMPlus 代码模板 - 普通的 Windows 程序代码
.686
.Model Flat, StdCall
Option Casemap :None

Include MyHeader.inc
    
.CODE
START:
	;获取当前进程的句柄
	invoke GetModuleHandle,NULL
	mov hInstance,eax
	invoke WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULT
	invoke ExitProcess,0

WinMain proc hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD
	LOCAL wc   :WNDCLASSEX
	LOCAL msg  :MSG
	local hWnd :HWND
	local hAccelerator
	local hDC  :HDC
	
	mov wc.cbSize,sizeof WNDCLASSEX
	mov wc.style,CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW or CS_OWNDC
	mov wc.lpfnWndProc,offset WndProc
	mov wc.cbClsExtra,NULL
	mov wc.cbWndExtra,NULL
	push hInst
	pop wc.hInstance
	invoke GetStockObject,WHITE_BRUSH
	mov wc.hbrBackground,eax
	mov wc.lpszMenuName,NULL
	mov wc.lpszClassName,offset szClassName
	;加载程序的光标和图标
	invoke LoadIcon,hInst,IDI_ICON;29874
	mov wc.hIcon,eax
	mov hIcon,eax
	invoke LoadIcon,hInst,IDI_ICON_SM
	mov wc.hIconSm,eax
	invoke LoadCursor,NULL,IDC_ARROW
	mov wc.hCursor,eax
	mov wc.hIconSm,0
	;注册类窗口
	invoke RegisterClassEx, ADDR wc
	.IF eax == 0
		call ErrorHandler
		jmp ExitProgram
	.ENDIF
	;创建应用程序的主窗口
	invoke CreateWindowEx,WM_EX_MyStyle,ADDR szClassName,CTXT("查看键盘消息 1号程序"),WM_EX_MyWinStyle,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInst,NULL
	;如果CreateWindowEx失败,显示一条消息并退出
	;显示欢迎消息
	.IF eax == 0
		call ErrorHandler
		jmp ExitProgram
	.ENDIF
	mov hWnd,eax
	invoke ShowWindow,hWnd,SW_SHOWNORMAL
	invoke UpdateWindow,hWnd
	INVOKE LoadAccelerators,hInst,IDA_MAIN
	Message_Loop:
		invoke GetMessage,ADDR msg,NULL,0,0
			cmp eax, 0
			je ExitProgram
				invoke TranslateMessage, ADDR msg
				invoke DispatchMessage, ADDR msg
			jmp Message_Loop
ExitProgram:
mov eax,msg.wParam
ret
WinMain endp

END START